package com.cskaoyan.typehandler;


import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import org.apache.ibatis.type.*;

import java.sql.*;

@MappedTypes(String.class)
@MappedJdbcTypes(JdbcType.DATE)
public class CustomTypeHandler implements TypeHandler<String> {
    @SneakyThrows
    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
        Date date = Date.valueOf(s);
        preparedStatement.setDate(i, date);
    }

    @Override
    public String getResult(ResultSet resultSet, String s) throws SQLException {
        return resultSet.getString(s);
    }

    @Override
    public String getResult(ResultSet resultSet, int i) throws SQLException {
        return resultSet.getString(i);
    }

    @Override
    public String getResult(CallableStatement callableStatement, int i) throws SQLException {
        return callableStatement.getString(i);
    }
}
